package com.eleadmin.ocean.controller;

import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.common.core.web.*;
import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.ocean.entity.OceanBulkCargo;
import com.eleadmin.ocean.service.OceanBulkCargoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 海运散货
 * @author : Doman
 * @date : 2023-10-25 15:36:44
 * @version ：1.0
 */

@Api(tags = "海运散货")
@RestController
@RequestMapping("/api/ocean/oceanBulkCargo")
public class OceanBulkCargoController extends BaseController {

    @Autowired
    private OceanBulkCargoService oceanBulkCargoService;

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargo:list')")
    //@ApiOperation("分页查询海运散货")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, OceanBulkCargo oceanBulkCargo) throws Exception{
        return oceanBulkCargoService.list(page, oceanBulkCargo, getLoginUser());
    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargo:list')")
    //@ApiOperation("查询全部海运散货")
    @GetMapping()
    public JsonResult list(OceanBulkCargo oceanBulkCargo){
        return oceanBulkCargoService.list(oceanBulkCargo, getLoginUser());
    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargo:list')")
    //@ApiOperation("根据id查询海运散货")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return oceanBulkCargoService.getById(id);
    }


    @PreAuthorize("hasAuthority('ocean:oceanBulkCargo:save')")
    @OperationLog
    @ApiOperation(value ="添加海运散货")
    @PostMapping()
    public JsonResult save(@RequestBody OceanBulkCargo oceanBulkCargo) {
        try {
            return oceanBulkCargoService.save(oceanBulkCargo, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargo:update')")
    @OperationLog
    @ApiOperation(value ="修改海运散货")
    @PutMapping()
    public JsonResult update(@RequestBody OceanBulkCargo oceanBulkCargo) {
        try {
            return oceanBulkCargoService.update(oceanBulkCargo, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargo:remove')")
    @OperationLog
    @ApiOperation(value ="删除海运散货")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") String id) {
        try {
            return oceanBulkCargoService.remove(id, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

}
